package users

import (
	"fmt"
	"github.com/aimuz/wgo"
	"github.com/gin-gonic/gin"
	//"github.com/mustache-cn/auths"
	"github.com/tiantour/union/wechat"
)

/*
获取UUID -> uuidMarauder
根据UUID获取二维码 -> qrcodeMarauder
显示二维码 -> qrcodeHttpCreator
扫码登陆 -> loginExecutor
*/

func (view *UserView) getWechatView(ctx *gin.Context) {
	wechat.AppID = "wx382007e2d65819ef"
	wechat.AppSecret = "9f6244823dda00e6c1228ee4c845f2bd"
	user, err := wechat.NewWechat().User("olgoN6-Czavm1ryjgpDdEo5rxtiQ")
	fmt.Println(user, err)
	//wxAuth := oauth.NewAuthWxWechat(Conf)
	////fmt.Print(wxAuth.GetRedirectUrl("sate")) //获取第三方登录地址
	//codeRes, _ := wxAuth.GetRedirectUrl("")
	//wxRes, _ := wxAuth.GetWebAccessToken(string(codeRes.Code))
	//userInfo, _ := wxAuth.GetUserInfo(wxRes.AccessToken, wxRes.OpenId)
	ctx.JSON(200, gin.H{
		"status": 0,
		"msg":    "get success",
		"data":   "userInfo",
	})
}

func (view *UserView) getWechat2View(ctx *gin.Context) {

	client := wgo.NewClient(wgo.WithAPPIDAndSecret("wx382007e2d65819ef", "9f6244823dda00e6c1228ee4c845f2bd"))
	req := wgo.GetQRCodeRequest{
		Path:      "https://www.baidu.com/",
		Width:     100,
		AutoColor: true,
		LineColor: wgo.QRCodeLineColor{
			R: 100,
			G: 100,
			B: 100,
		},
		IsHyaline: true,
	}
	GetQRCodeRes, _ := client.GetQRCode(ctx, &req)
	fmt.Println(GetQRCodeRes)

	AccessTokenRes, _ := client.GetAccessToken(ctx)
	fmt.Println(AccessTokenRes)

	ctx.JSON(200, gin.H{
		"status": 0,
		"msg":    "get success",
		"data":   "userInfo",
	})
}

func (view *UserView) getQQView(ctx *gin.Context) {

	//Conf := &oauth.AuthConfig{
	//	ClientId:     "wx382007e2d65819ef",
	//	ClientSecret: "9f6244823dda00e6c1228ee4c845f2bd",
	//	RedirectUrl:  "http://49.234.17.113:3000/#/user/login"}
	//
	//dyAuth := oauth.NewAuthQq(Conf)
	//coderes, err := dyAuth.GetRedirectUrl("")
	//TokenRes, err := dyAuth.GetToken(string(coderes.Code))
	//UserRes, err := dyAuth.GetUserInfo(TokenRes.OpenId, TokenRes.AccessToken)
	//fmt.Println(UserRes)
	//fmt.Println(err)

	ctx.JSON(200, gin.H{
		"status": 0,
		"msg":    "get success",
		"data":   "userInfo",
	})
}

//func (view *UserView) loginByAuths(ctx *gin.Context) {
//	client_id := "wxa83ee981960d8518"
//	client_secret := "915bc0bd56d08515867197c45363f5c4"
//	builder := auths.NewAuths(client_id, client_secret, auths.Wechat).SetCode("code").Build()
//	token, err := builder.AccessToken()
//	if err != nil {
//		return
//	}
//	fmt.Println(token)
//	info, err := builder.UserInfo()
//	if err != nil {
//		return
//	}
//	fmt.Println(info)
//
//	ctx.JSON(200, gin.H{
//		"status": 0,
//		"msg":    "get success",
//		"data":   "userInfo",
//	})
//}
